#ifndef		_KHEAP_H_
#define		_KHEAP_H_

#include	"common.h"
#include	"ordered_map.h"

#define		KHEAP_START		0xC0000000
#define		KHEAP_INITSIZE		0x100000
#define		KHEAP_INDEXSIZE		0x20000
#define		KHEAP_MAGIC		0x123890AB
#define		KHEAP_MINSIZE		0x70000

#define		UHEAP_START		0xD0000000
#define		UHEAP_INITSIZE		0x100000
#define		UHEAP_INDEXSIZE		0x20000
#define		UHEAP_MAGIC		0x123890AB
#define		UHEAP_MINSIZE		0x70000

struct header{
	u32int magic;
	u8int is_hole;
	u32int size;
};

struct footer{
	u32int magic;
	struct header *header;
};

struct heap{
	struct ordered_map index;
	u32int start_address, end_address, max_address;
	u8int supervisor, readonly;
};

struct heap *create_heap(u32int start, u32int end, u32int max, u8int supervisor, u8int readonly);
void *alloc(u32int size, u8int align, struct heap *pheap);
void free(void *p, struct heap *pheap);

u32int kmalloc_int(u32int sz, int align, u32int *phys);
u32int kmalloc(u32int sz);
u32int kmalloc_a(u32int sz);
u32int kmalloc_p(u32int sz, u32int *phys);
u32int kmalloc_ap(u32int sz, u32int *phys);
void kfree(void *p);

u32int umalloc_int(u32int sz, int align, u32int *phys);
u32int umalloc(u32int sz);
u32int umalloc_a(u32int sz);
u32int umalloc_p(u32int sz, u32int *phys);
u32int umalloc_ap(u32int sz, u32int *phys);
void ufree(void *p);

#endif		/* _KHEAP_H_ */
